import "bootstrap/dist/css/bootstrap.css"
import "bootstrap/dist/js/bootstrap.js"
import "@scss/header.scss"
import "@scss/examinationProcess.scss"
import "@scss/inTheExam.scss"
import $ from "jquery"
import http from "../utils/request.js";
import { renderTestAnalysis ,renderName} from "./render.js";



// 解析渲染
(function () {

    renderTestAnalysis();
    renderName()
})();



//选题号按钮
//判断是否选中

$('body').on('click', '#anwer-btns', function(e) {
    const buttons = $(this).children();
    for (let i = 0; i < buttons.length; i++) {
        if ($(buttons[i]).attr('data-flag')) {
            $(buttons[i]).attr('class', 'greenBack');
        } else {
            $(buttons[i]).attr('class', '');
        }
    }

    const $this = $(e.target);
    //获取对应按钮的题目class
    const $thisShowQusetionClass = $this.attr("id").split('-')[0];
    //对应题目显示
    $('.carousel-item').hide();
    $(`.${$thisShowQusetionClass}`).show();
    $(`.${$thisShowQusetionClass}`).addClass('active').siblings("div").removeClass('active');

    //如果按钮未选中状态
    if ($this.attr('class') == '') {
        //点击变成答题状态
        $this.addClass('inTheAns');
    } else if ($this.attr('class').indexOf('greenBack') != -1) {
        $this.addClass('inTheAns').removeClass('greenBack');
    }

})


//选项选择
$('body').on('click', '.options dd', function() {
    $(this).addClass('activeErr').siblings().removeClass('activeErr');
    let ss = $(this).parents("div").attr('class').split(' ')[1];
    $(`#${ss}-btn`).attr('data-flag', true);

});
//点击下一题
$('body').on('click', '.testBtn', function() {

    if ($($(this).parents()[1]).next().length > 0) {
        $('.carousel-item').hide();
        $($(this).parents()[1]).next().show();
        const selectBtnClass = $($(this).parents()[1]).next().attr('class').split(' ')[1];
        if ($(`#${selectBtnClass}-btn`).prev().attr('data-flag')) {
            $(`#${selectBtnClass}-btn`).attr('class', 'inTheAns').prev().attr('class', 'greenBack');
        } else {
            $(`#${selectBtnClass}-btn`).attr('class', 'inTheAns').prev().attr('class', '');
        }
    } else if ($($(this).parents()[1]).next().length == 0) {
        alert('最后一题');
    }

});


